{% extends "../../main.html" %}

{% block title %}{{ _("Market Objects") }}{% end %}

{% block header %}
<script src="/static/js/pages/admin/view/market_objects.js"></script>
{% end %}

{% block modals %}
{% from tornado.options import options %}
<!-- Hidden Edit Form -->
<div id="edit-market-item-modal" class="modal hide fade" style="display: none; ">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h3>
            <i class="fa fa-pencil"></i>
            {{ _("Edit Market Item") }}
        </h3>
    </div>
    <div class="modal-body">
        <br />
        <form id="edit-market-item-form" class="form-horizontal" action="/admin/edit/market_item" method="post">
            {% raw xsrf_form_html() %}
            <input type="hidden" id="edit-market-item-uuid" name="item_uuid" value="" />
            <div class="control-group">
                <label class="control-label" for="price">{{ _("Item Cost") }}</label>
                <div class="controls">
                    <input required pattern="[0-9]+" id="edit-market-item-price" name="price" type="text" placeholder="{{ _('Item Price')}})">
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">{{ _("Close") }}</a>
        <button id="edit-market-item-submit" type="button" class="btn btn-primary">
            <i class="fa fa-save"></i>
            {{ _("Save") }}
        </button>
    </div>
</div>
{% end %}

{% block content %}
{% from models.MarketItem import MarketItem %}
<div class="container">
    <h2>
        <i class="fa fa-shopping-cart"></i>
        {{ _("Manage Black Market") }}
    </h2>
    <br />
    {% if errors is not None and len(errors) != 0 %}
        {% for error in errors %}
              <div class="alert alert-error">
                <a class="close" data-dismiss="alert" href="#">&times;</a>
                <h4 class="alert-heading">{{ _("ERROR") }}</h4>
                {{ error }}
              </div>
        {% end %}
      {% end %}
      <div class="well">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>#</th>
                    <th>{{ _("Name") }}</th>
                    <th style="text-align: center; padding-right: 20px;">{% if options.banking %}{{ _("Price") }}{% else %}{{ _("Points") }}{% end %}</th>
                    <th><!-- Button --></th>
                </tr>
            </thead>
            <tbody>
                {% for index, item in enumerate(MarketItem.all()) %}
                    <tr>
                        <td class="shortcolumn">{{ index + 1 }}</td>
                        <td>{{ item.name }}</td>
                        <td class="shortcolumn" style="text-align: center; padding-right: 20px;">{% if options.banking %}${% end %}{{ item.price }}</td>
                        <td class="shortcolumn">
                            <a id="edit-market-item-button{{ index }}" class="btn btn-mini" data-toggle="modal" href="#edit-market-item-modal" data-uuid="{{ item.uuid }}" data-price="{{ item.price }}">
                                <i class="fa fa-pencil"></i>
                                {{ _("Edit") }}
                            </a>
                        </td>
                    </tr>
                {% end %}
            </tbody>
        </table>
    </div>
</div>
{% end %}